﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StrategyPattern
{
    /// <summary>
    /// 策略方式
    /// </summary>
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        double total = 0.0d;
        private void button1_Click(object sender, EventArgs e)
        {
            double totalprices = 0d;
            CashContext cashSuper = new CashContext(comboBox1.SelectedItem.ToString());
            totalprices = cashSuper.GetResult(Convert.ToDouble(txtprice.Text) * Convert.ToDouble(txtpnumber.Text));
            total = total + totalprices;


            //switch (comboBox1.SelectedIndex)
            //{
            //    case 0:
            //        totalprices = Convert.ToDouble(txtprice.Text) * Convert.ToDouble(txtprice.Text);
            //        break;
            //    case 1:
            //        totalprices = Convert.ToDouble(txtprice.Text) * Convert.ToDouble(txtprice.Text)*0.8;
            //        break;
            //    case 2:
            //        totalprices = Convert.ToDouble(txtprice.Text) * Convert.ToDouble(txtprice.Text)*0.7;
            //        break;
            //    case 3:
            //        totalprices = Convert.ToDouble(txtprice.Text) * Convert.ToDouble(txtprice.Text)*0.5;
            //        break;

            //    default:
            //        break;
            //}

            total = total + totalprices;
            listView1.Items.Add("单价：" + txtprice.Text + "数量：" + txtpnumber.Text +"方式："+comboBox1.SelectedItem+ "合计：" + totalprices.ToString());
            label1.Text = total.ToString();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.Items.AddRange(new object[] { "正常收费", "满300返100", "打8折"});
            comboBox1.SelectedIndex = 0;
        }
    }
}
